﻿using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace TL2
{
    public partial class MainForm : Form
    {
        public delegate void SimpleDelegate();
        private string file;
        private string text;
        public MainForm()
        {
            InitializeComponent();
        }

        private void TxtLoaded()
        {
            InfoLabel.Text = "Txt loaded : " + file;
        }

        private void TxtNotLoaded()
        {
            InfoLabel.Text = "No txt loaded";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SimpleDelegate simpleDelegate = new SimpleDelegate(TxtNotLoaded);
            simpleDelegate();
        }

        private void LoadTxtBtn_Click(object sender, EventArgs e)
        {
            UserChoose();
        }

        private void CleanTxtBtn_Click(object sender, EventArgs e)
        {
            if (file!=null)
            {
                string cleanedTxt = CleanHtmlTags.Clean(TxtController.ReadTxt(file));
                if (cleanedTxt != null)
                {
                    string newName = file.Substring(0, file.Length - 4);
                    if (TxtController.WriteTxt(newName + "tl1.txt", cleanedTxt) == 1)
                    {
                        Messages.Messanger("Η Δουλεία έγινε");
                    }
                }
            }
        }

        private void UserChoose()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                file = openFileDialog1.FileName;
                SimpleDelegate simpleDelegate = new TL2.MainForm.SimpleDelegate(TxtLoaded);
                simpleDelegate();
            }
        }      
    }
}
